<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once 'Zend/Db/Table/Abstract.php';
class Admin_Models_AdminNewsModel extends Zend_Db_Table_Abstract
{
    /**
     * The default table name 
     */
    protected $_name = 'tbl_admin_news';
    protected $_primary = 'idnote';
    function search($search,$field){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from('tbl_admin_news')->where($field ." LIKE '%".$search."%'");
//        echo $mySql;
//        die;
        $result = $db->fetchAll($mySql);
        return $result;
    }
     function loadnotebyid($id){
         $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from('tbl_admin_news')->where('idnote = '.$id);
//        echo $mySql;
//        die;
        $result = $db->fetchAll($mySql);
        return $result;
    }
    function loadlist(){
       $db = Zend_Db_Table::getDefaultAdapter();
       $sql = $db->select()->from('tbl_admin_news')->order('time_date DESC');
       $result = $db->fetchAll($sql);
       return $result;        
    }
    function loadlistgame(){
         $db = Zend_Db_Table::getDefaultAdapter();
       $sql = $db->select()->from('product',array('ProductID','Title'));
       $result = $db->fetchAll($sql);
       return $result;        
    }
    function loaduserinfobyid($uid){
        $db = Zend_Db_Table::getDefaultAdapter();  
        $sql=$db->select()->from('userinfo',array("UserID","Username","Avatar"))->where("UserID='".$uid."'");

        $result = $db->fetchAll($sql);
        return $result;
    }
     public function getProductById($ProductID){
            $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        	$mySql = $db->select()
        				->from($this->_name)
                        ->where('ProductID = ?',$ProductID);
            
            $result = $db->fetchRow($mySql);
            return $result;
    }
        function updatenote($data,$id){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql=$db->update('tbl_admin_news', $data, 'idnote='.$id);
        return $mySql;
    }
}
?>
